package net.mysoftworks.bm;

import java.io.File;

public class FilenameAndPatternFilter extends NoSVNFileFilter {

	private String filename;
	private String patternMatch;
	private String patternNotMatch;
	
	public FilenameAndPatternFilter(String filename, String patternMatch, String patternNotMatch) {
		super();
		this.filename = filename;
		this.patternMatch = patternMatch;
		this.patternNotMatch = patternNotMatch;
	}

	@Override
	public boolean accept(File dir, String name) {
		if (!super.accept(dir, name)) return false;
		File inner = new File(dir,name);
		boolean accept = inner.isDirectory();
		if (!accept && filename!=null) {
			accept = accept || name.equals(filename);
		}
//		&& (name.equals(filename) || new File(dir,name).isDirectory());
		if (accept && patternMatch!=null) {
			accept = accept && (dir.getAbsolutePath() + name).matches(patternMatch) ;
		}
		if (accept && patternNotMatch!=null) {
			accept = accept && !(dir.getAbsolutePath() + name).matches(patternNotMatch) ;
		}
		return accept;
	}



}
